﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GTA.UserControls.Tools
{
    public partial class UcGeneral : BaseUserControl
    {
        #region Properties
        public String ValidationErrorMessage
        {
            get { return GetValidationErrorMessage(); }
        }
        #endregion

        #region Starting Control
        public UcGeneral()
        {
            InitializeComponent();
        }
        private void UcGeneral_Load(object sender, EventArgs e)
        {
            StartControl();
        }
        private void StartControl()
        {
            LoadConfiguration(Program.SystemConfiguration.General);
        }
        #endregion

        #region Events
        private void cmdSelectColorStatusFinalizado_Click(object sender, EventArgs e)
        {
            SelectColorStatusFinalizado();
        }
        private void cmdSelectColorStatusAtrasoEntrega_Click(object sender, EventArgs e)
        {
            SelectColorStatusAtrasoEntrega();
        }
        private void cmdSelectColorStatusAtrasoInicio_Click(object sender, EventArgs e)
        {
            SelectColorStatusAtrasoInicio();
        }
        private void cmdSelectColorStatusAlertaEntrega_Click(object sender, EventArgs e)
        {
            SelectColorStatusAlertaEntrega();
        }
        private void cmdSelectColorStatusAlertaInicio_Click(object sender, EventArgs e)
        {
            SelectColorStatusAlertaInicio();
        }
        private void cmdSelectColorStatusCancelado_Click(object sender, EventArgs e)
        {
            SelectColorStatusCancelado();
        }
        private void cmdSelectForeColorStatusFinalizado_Click(object sender, EventArgs e)
        {
            SelectForeColorStatusFinalizado();
        }
        private void cmdSelectForeColorStatusAtrasoEntrega_Click(object sender, EventArgs e)
        {
            SelectForeColorStatusAtrasoEntrega();
        }
        private void cmdSelectForeColorStatusAtrasoInicio_Click(object sender, EventArgs e)
        {
            SelectForeColorStatusAtrasoInicio();
        }
        private void cmdSelectForeColorStatusAlertaEntrega_Click(object sender, EventArgs e)
        {
            SelectForeColorStatusAlertaEntrega();
        }
        private void cmdSelectForeColorStatusAlertaInicio_Click(object sender, EventArgs e)
        {
            SelectForeColorStatusAlertaInicio();
        }
        private void cmdSelectForeColorStatusCancelado_Click(object sender, EventArgs e)
        {
            SelectForeColorStatusCancelado();
        }
        #endregion

        #region Methods
        private void LoadConfiguration(BusinessEntity.Configuration.General configuration)
        {
            ckTryIcon.Checked = configuration.HideOnTryIcon;
            txtSearchTimeSummaryArchitects.Text = configuration.TimeSearchInformativeSummaryArchitects.ToString();
            txtSearchTimeSummaryProjects.Text = configuration.TimeSearchInformativeSummaryProjects.ToString();
            txtSearchTimeSummaryStatus.Text = configuration.TimeSearchInformativeSummaryStates.ToString();
            txtSearchTimeSummaryCategories.Text = configuration.TimeSearchInformativeSummaryCategories.ToString();
            txtSearchTimeAlerts.Text = configuration.TimeAlert.ToString();
            pnlStatusAlertaEntrega.BackColor = Color.FromArgb(configuration.StatusColor.StatusAlertaEntregaBackColor.Red, configuration.StatusColor.StatusAlertaEntregaBackColor.Green, configuration.StatusColor.StatusAlertaEntregaBackColor.Blue);
            pnlStatusAlertaInicio.BackColor = Color.FromArgb(configuration.StatusColor.StatusAlertaInicioBackColor.Red, configuration.StatusColor.StatusAlertaInicioBackColor.Green, configuration.StatusColor.StatusAlertaInicioBackColor.Blue);
            pnlStatusAtrasoEntrega.BackColor = Color.FromArgb(configuration.StatusColor.StatusAtrasoEntregaBackColor.Red, configuration.StatusColor.StatusAtrasoEntregaBackColor.Green, configuration.StatusColor.StatusAtrasoEntregaBackColor.Blue);
            pnlStatusAtrasoInicio.BackColor = Color.FromArgb(configuration.StatusColor.StatusAtrasoInicioBackColor.Red, configuration.StatusColor.StatusAtrasoInicioBackColor.Green, configuration.StatusColor.StatusAtrasoInicioBackColor.Blue);
            pnlStatusCancelado.BackColor = Color.FromArgb(configuration.StatusColor.StatusCanceladoBackColor.Red, configuration.StatusColor.StatusCanceladoBackColor.Green, configuration.StatusColor.StatusCanceladoBackColor.Blue);
            pnlStatusFinalizado.BackColor = Color.FromArgb(configuration.StatusColor.StatusFinalizadoBackColor.Red, configuration.StatusColor.StatusFinalizadoBackColor.Green, configuration.StatusColor.StatusFinalizadoBackColor.Blue);
            pnlForeColorStatusAlertaEntrega.BackColor = Color.FromArgb(configuration.StatusColor.StatusAlertaEntregaForeColor.Red, configuration.StatusColor.StatusAlertaEntregaForeColor.Green, configuration.StatusColor.StatusAlertaEntregaForeColor.Blue);
            pnlForeColorStatusAlertaInicio.BackColor = Color.FromArgb(configuration.StatusColor.StatusAlertaInicioForeColor.Red, configuration.StatusColor.StatusAlertaInicioForeColor.Green, configuration.StatusColor.StatusAlertaInicioForeColor.Blue);
            pnlForeColorStatusAtrasoEntrega.BackColor = Color.FromArgb(configuration.StatusColor.StatusAtrasoEntregaForeColor.Red, configuration.StatusColor.StatusAtrasoEntregaForeColor.Green, configuration.StatusColor.StatusAtrasoEntregaForeColor.Blue);
            pnlForeColorStatusAtrasoInicio.BackColor = Color.FromArgb(configuration.StatusColor.StatusAtrasoInicioForeColor.Red, configuration.StatusColor.StatusAtrasoInicioForeColor.Green, configuration.StatusColor.StatusAtrasoInicioForeColor.Blue);
            pnlForeColorStatusCancelado.BackColor = Color.FromArgb(configuration.StatusColor.StatusCanceladoForeColor.Red, configuration.StatusColor.StatusCanceladoForeColor.Green, configuration.StatusColor.StatusCanceladoForeColor.Blue);
            pnlForeColorStatusFinalizado.BackColor = Color.FromArgb(configuration.StatusColor.StatusFinalizadoForeColor.Red, configuration.StatusColor.StatusFinalizadoForeColor.Green, configuration.StatusColor.StatusFinalizadoForeColor.Blue);
        }
        internal bool ValidateForm()
        {
            return !String.IsNullOrEmpty(txtSearchTimeSummaryArchitects.Text.Trim()) &&
                   !String.IsNullOrEmpty(txtSearchTimeSummaryProjects.Text.Trim()) &&
                   !String.IsNullOrEmpty(txtSearchTimeSummaryStatus.Text.Trim()) &&
                   !String.IsNullOrEmpty(txtSearchTimeSummaryCategories.Text.Trim()) &&
                   !String.IsNullOrEmpty(txtSearchTimeAlerts.Text.Trim()) &&
                   Convert.ToInt32(txtSearchTimeSummaryArchitects.Text.Trim()) >= 60 &&
                   Convert.ToInt32(txtSearchTimeSummaryProjects.Text.Trim()) >= 60 &&
                   Convert.ToInt32(txtSearchTimeSummaryStatus.Text.Trim()) >= 60 &&
                   Convert.ToInt32(txtSearchTimeSummaryCategories.Text.Trim()) >= 60 &&
                   Convert.ToInt32(txtSearchTimeAlerts.Text.Trim()) >= 60;
        }
        private string GetValidationErrorMessage()
        {
            StringBuilder message = new StringBuilder();
            if (String.IsNullOrEmpty(txtSearchTimeSummaryArchitects.Text.Trim()))
                message.Append("\r\nInforme o tempo de pesquisa para o resumo informativo de Arquitetos");
            if (String.IsNullOrEmpty(txtSearchTimeSummaryProjects.Text.Trim()))
                message.Append("\r\nInforme o tempo de pesquisa para o resumo informativo de Projetos");
            if (String.IsNullOrEmpty(txtSearchTimeSummaryStatus.Text.Trim()))
                message.Append("\r\nInforme o tempo de pesquisa para o resumo informativo de Status");
            if (String.IsNullOrEmpty(txtSearchTimeSummaryCategories.Text.Trim()))
                message.Append("\r\nInforme o tempo de pesquisa para o resumo informativo de Categorias");
            if (String.IsNullOrEmpty(txtSearchTimeAlerts.Text.Trim()))
                message.Append("\r\nInforme o tempo de pesquisa para os Alertas");
            if (!String.IsNullOrEmpty(txtSearchTimeSummaryArchitects.Text.Trim()) &&
                Convert.ToInt32(txtSearchTimeSummaryArchitects.Text.Trim()) < 60)
                message.Append("\r\nO tempo minimo de pesquisa para o resumo informativo de Arquitetos é de 1 minuto (60 segundos)");
            if (!String.IsNullOrEmpty(txtSearchTimeSummaryProjects.Text.Trim()) &&
                Convert.ToInt32(txtSearchTimeSummaryProjects.Text.Trim()) < 60)
                message.Append("\r\nO tempo minimo de pesquisa para o resumo informativo de Projetos é de 1 minuto (60 segundos)");
            if (!String.IsNullOrEmpty(txtSearchTimeSummaryStatus.Text.Trim()) &&
                Convert.ToInt32(txtSearchTimeSummaryStatus.Text.Trim()) < 60)
                message.Append("\r\nO tempo minimo de pesquisa para o resumo informativo de Status é de 1 minuto (60 segundos)");
            if (!String.IsNullOrEmpty(txtSearchTimeSummaryCategories.Text.Trim()) &&
                Convert.ToInt32(txtSearchTimeSummaryCategories.Text.Trim()) < 60)
                message.Append("\r\nO tempo minimo de pesquisa para o resumo informativo de Categorias é de 1 minuto (60 segundos)");
            if (!String.IsNullOrEmpty(txtSearchTimeAlerts.Text.Trim()) &&
                Convert.ToInt32(txtSearchTimeAlerts.Text.Trim()) < 60)
                message.Append("\r\nO tempo minimo de pesquisa para os Alertas é de 1 minuto (60 segundos)");
            return message.ToString();
        }
        internal BusinessEntity.Configuration.General GetGeneralConfiguration()
        {
            BusinessEntity.Configuration.General configuration = new GTA.BusinessEntity.Configuration.General();
            configuration.HideOnTryIcon = ckTryIcon.Checked;
            configuration.TimeSearchInformativeSummaryArchitects = Convert.ToInt32(txtSearchTimeSummaryArchitects.Text);
            configuration.TimeSearchInformativeSummaryProjects = Convert.ToInt32(txtSearchTimeSummaryProjects.Text);
            configuration.TimeSearchInformativeSummaryStates = Convert.ToInt32(txtSearchTimeSummaryStatus.Text);
            configuration.TimeSearchInformativeSummaryCategories = Convert.ToInt32(txtSearchTimeSummaryCategories.Text);
            configuration.TimeAlert = Convert.ToInt32(txtSearchTimeAlerts.Text);
            configuration.StatusColor.StatusAlertaEntregaBackColor = new GTA.BusinessEntity.Configuration.TaskStatusColor.Color(pnlStatusAlertaEntrega.BackColor.R, pnlStatusAlertaEntrega.BackColor.G, pnlStatusAlertaEntrega.BackColor.B);
            configuration.StatusColor.StatusAlertaInicioBackColor = new GTA.BusinessEntity.Configuration.TaskStatusColor.Color(pnlStatusAlertaInicio.BackColor.R, pnlStatusAlertaInicio.BackColor.G, pnlStatusAlertaInicio.BackColor.B);
            configuration.StatusColor.StatusAtrasoEntregaBackColor = new GTA.BusinessEntity.Configuration.TaskStatusColor.Color(pnlStatusAtrasoEntrega.BackColor.R, pnlStatusAtrasoEntrega.BackColor.G, pnlStatusAtrasoEntrega.BackColor.B);
            configuration.StatusColor.StatusAtrasoInicioBackColor = new GTA.BusinessEntity.Configuration.TaskStatusColor.Color(pnlStatusAtrasoInicio.BackColor.R, pnlStatusAtrasoInicio.BackColor.G, pnlStatusAtrasoInicio.BackColor.B);
            configuration.StatusColor.StatusCanceladoBackColor = new GTA.BusinessEntity.Configuration.TaskStatusColor.Color(pnlStatusCancelado.BackColor.R, pnlStatusCancelado.BackColor.G, pnlStatusCancelado.BackColor.B);
            configuration.StatusColor.StatusFinalizadoBackColor = new GTA.BusinessEntity.Configuration.TaskStatusColor.Color(pnlStatusFinalizado.BackColor.R, pnlStatusFinalizado.BackColor.G, pnlStatusFinalizado.BackColor.B);
            configuration.StatusColor.StatusAlertaEntregaForeColor = new GTA.BusinessEntity.Configuration.TaskStatusColor.Color(pnlForeColorStatusAlertaEntrega.BackColor.R, pnlForeColorStatusAlertaEntrega.BackColor.G, pnlForeColorStatusAlertaEntrega.BackColor.B);
            configuration.StatusColor.StatusAlertaInicioForeColor = new GTA.BusinessEntity.Configuration.TaskStatusColor.Color(pnlForeColorStatusAlertaInicio.BackColor.R, pnlForeColorStatusAlertaInicio.BackColor.G, pnlForeColorStatusAlertaInicio.BackColor.B);
            configuration.StatusColor.StatusAtrasoEntregaForeColor = new GTA.BusinessEntity.Configuration.TaskStatusColor.Color(pnlForeColorStatusAtrasoEntrega.BackColor.R, pnlForeColorStatusAtrasoEntrega.BackColor.G, pnlForeColorStatusAtrasoEntrega.BackColor.B);
            configuration.StatusColor.StatusAtrasoInicioForeColor = new GTA.BusinessEntity.Configuration.TaskStatusColor.Color(pnlForeColorStatusAtrasoInicio.BackColor.R, pnlForeColorStatusAtrasoInicio.BackColor.G, pnlForeColorStatusAtrasoInicio.BackColor.B);
            configuration.StatusColor.StatusCanceladoForeColor = new GTA.BusinessEntity.Configuration.TaskStatusColor.Color(pnlForeColorStatusCancelado.BackColor.R, pnlForeColorStatusCancelado.BackColor.G, pnlForeColorStatusCancelado.BackColor.B);
            configuration.StatusColor.StatusFinalizadoForeColor = new GTA.BusinessEntity.Configuration.TaskStatusColor.Color(pnlForeColorStatusFinalizado.BackColor.R, pnlForeColorStatusFinalizado.BackColor.G, pnlForeColorStatusFinalizado.BackColor.B);
            return configuration;
        }
        private void SelectColorStatusFinalizado()
        {
            colorDialogStatus.Color = pnlStatusFinalizado.BackColor;
            if (colorDialogStatus.ShowDialog(this) == DialogResult.OK)
                pnlStatusFinalizado.BackColor = colorDialogStatus.Color;
        }
        private void SelectColorStatusAtrasoEntrega()
        {
            colorDialogStatus.Color = pnlStatusAtrasoEntrega.BackColor;
            if (colorDialogStatus.ShowDialog(this) == DialogResult.OK)
                pnlStatusAtrasoEntrega.BackColor = colorDialogStatus.Color;
        }
        private void SelectColorStatusAtrasoInicio()
        {
            colorDialogStatus.Color = pnlStatusAtrasoInicio.BackColor;
            if (colorDialogStatus.ShowDialog(this) == DialogResult.OK)
                pnlStatusAtrasoInicio.BackColor = colorDialogStatus.Color;
        }
        private void SelectColorStatusAlertaEntrega()
        {
            colorDialogStatus.Color = pnlStatusAlertaEntrega.BackColor;
            if (colorDialogStatus.ShowDialog(this) == DialogResult.OK)
                pnlStatusAlertaEntrega.BackColor = colorDialogStatus.Color;
        }
        private void SelectColorStatusAlertaInicio()
        {
            colorDialogStatus.Color = pnlStatusAlertaInicio.BackColor;
            if (colorDialogStatus.ShowDialog(this) == DialogResult.OK)
                pnlStatusAlertaInicio.BackColor = colorDialogStatus.Color;
        }
        private void SelectColorStatusCancelado()
        {
            colorDialogStatus.Color = pnlStatusCancelado.BackColor;
            if (colorDialogStatus.ShowDialog(this) == DialogResult.OK)
                pnlStatusCancelado.BackColor = colorDialogStatus.Color;
        }
        private void SelectForeColorStatusFinalizado()
        {
            colorDialogStatus.Color = pnlForeColorStatusFinalizado.BackColor;
            if (colorDialogStatus.ShowDialog(this) == DialogResult.OK)
                pnlForeColorStatusFinalizado.BackColor = colorDialogStatus.Color;
        }
        private void SelectForeColorStatusAtrasoEntrega()
        {
            colorDialogStatus.Color = pnlForeColorStatusAtrasoEntrega.BackColor;
            if (colorDialogStatus.ShowDialog(this) == DialogResult.OK)
                pnlForeColorStatusAtrasoEntrega.BackColor = colorDialogStatus.Color;
        }
        private void SelectForeColorStatusAtrasoInicio()
        {
            colorDialogStatus.Color = pnlForeColorStatusAtrasoInicio.BackColor;
            if (colorDialogStatus.ShowDialog(this) == DialogResult.OK)
                pnlForeColorStatusAtrasoInicio.BackColor = colorDialogStatus.Color;
        }
        private void SelectForeColorStatusAlertaEntrega()
        {
            colorDialogStatus.Color = pnlForeColorStatusAlertaEntrega.BackColor;
            if (colorDialogStatus.ShowDialog(this) == DialogResult.OK)
                pnlForeColorStatusAlertaEntrega.BackColor = colorDialogStatus.Color;
        }
        private void SelectForeColorStatusAlertaInicio()
        {
            colorDialogStatus.Color = pnlForeColorStatusAlertaInicio.BackColor;
            if (colorDialogStatus.ShowDialog(this) == DialogResult.OK)
                pnlForeColorStatusAlertaInicio.BackColor = colorDialogStatus.Color;
        }
        private void SelectForeColorStatusCancelado()
        {
            colorDialogStatus.Color = pnlForeColorStatusCancelado.BackColor;
            if (colorDialogStatus.ShowDialog(this) == DialogResult.OK)
                pnlForeColorStatusCancelado.BackColor = colorDialogStatus.Color;
        }
        #endregion
    }
}
